package com.example.exam.repository;

import com.example.exam.entity.ExamPaper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author shishuqian
 * date 2021/4/27
 * time 15:14
 **/
@Repository //不是必须的，加上后测试不会报红
public interface ExamPaperRepository extends JpaRepository<ExamPaper,Integer> {

    //查询用户创建的试卷,按照创建时间降序排列
    @Query(value = "SELECT p FROM ExamPaper p WHERE p.createUserId = ?1 AND p.deleted = false ORDER BY p.createTime DESC")
    List<ExamPaper> findExamPapersByCreateUserId(Integer userId);

    //分页查询用户创建的试卷,按照创建时间降序排列
    Page<ExamPaper> findByCreateUserIdAndDeletedOrderByCreateTimeDesc(Integer createUserId,Boolean deleted, Pageable pageable);

    //根据试卷名搜索试卷,按照创建时间降序排列
    Page<ExamPaper> findByTitleLikeAndCreateUserIdOrderByCreateTimeDesc(String title,Integer createUserId,Pageable pageable);
}
